
import config from '@/config/config.js';
import axios from "axios";

const deviceRequest = {
    loadAllDeviceList(deviceSearch,pageNum,limit,callback){
        let url = config.deviceBaseUrl + "/device/list?pageNum=" + pageNum + "&limit=" + limit + "&deviceTypeId=" + deviceSearch.deviceTypeId;
        if (deviceSearch.deviceId){
            url += "&deviceId=" + deviceSearch.deviceId
        }
        if (deviceSearch.deviceName){
            url += "&deviceName=" + deviceSearch.deviceName
        }
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    insertDevice(insertDevice,callback){
        let url = config.deviceBaseUrl + "/device/insert"
        axios.post(url,insertDevice,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    loadUpdateInfo(deviceId,callback){
        let url = config.deviceBaseUrl + "/device/getUpdate?deviceId=" + deviceId;
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    UpdateDevice(device,callback){
        let url = config.deviceBaseUrl + "/device/update";
        axios.put(url,device,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    deleteDevice(deviceId,callback){
        let url = config.deviceBaseUrl + "/device/delete?deviceId=" + deviceId;
        axios.delete(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    exportDevice(deviceSearch,pageNum,limit,callback){
        let url = config.deviceBaseUrl + "/device/export?pageNum=" + pageNum + "&limit=" + limit + "&deviceTypeId=" + deviceSearch.deviceTypeId;
        if (deviceSearch.deviceId){
            url += "&deviceId=" + deviceSearch.deviceId
        }
        if (deviceSearch.deviceName){
            url += "&deviceName=" + deviceSearch.deviceName
        }
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    }
}
export default deviceRequest;